import axios from "axios";

//新增商品
export async function addGoods(data) {
    let { name, pictures, price, description, tag } = data;
    // let { name, price, description, tag } = obj;//解构
    let resp = await axios.post("/api/goods/", {
        name,
        pictures,
        price,
        description,
        tag
    });
    console.log(resp);
    return resp;
}

//删除商品
export async function deleteGoods(_id) {
    await axios.delete("/api/goods/" + _id);

}

//查询所有商品
export async function getAllGoods(page, pageSize) {//传参，把数据请求回后台
    let resp = await axios.get("/api/goods", {
        params: {
            current: page,//当前页。第几页
            pageSize,//每页显示条数
        }
    });
    return resp;//响应，后台把数据响应回来
}
//分类查询
export async function getGoodsType(form) {
    let { type,value } = form;//解构，根后台匹配
    console.log(type,value);
    let resp = await axios.get("/api/goods/", {
        params: {
            type,
            value
        }
    });
    return resp;  
}

//修改商品
export async function changeGoods(id,name, price, description, tag) {
    let resp = await axios.put("/api/goods/" + id, {
        name, price, description, tag
    })
    return resp;
}


